import { YvEventDispatch } from './YvanEvent'
import webix from 'webix'

export default class CtlGridCellImage {
  $el: any
  $btns!: any[]
  func!: any[]

  init(params: any) {
    this.$el = document.createElement('div')
    this.$el.style.width="100%";
    this.$el.style.height="100%";
    this._buildHTML.call(this, params)
  }

  getGui() {
    return this.$el
  }

  destroy() {

  }

  refresh(params: any) {
    this._buildHTML.call(this, params)
  }

  private _buildHTML(this: any, params: any) {
    const arr: Array<any> = []

    const { images, rowIndex, data, api, column } = params

    const value = data[column.colId];

    if (images) {
      const r = YvEventDispatch(images, params.api.vue,{
        rowIndex, data, column
      });
      this.$el.innerHTML = r;
    }


    // const divId = 'grid_cell_image_div' + webix.uid();
    // this.$el.innerHTML = `<div id="${divId}" class="yv-grid-buttons" style="width:100%;height:100%">` + arr.join('') + '</div>';
    //
    // //@ts-ignore
    // require(['viewerjs'], (Viewer: any) => {
    //   new Viewer(document.getElementById(divId), {
    //     url: 'data-original'
    //   });
    // })
  }
}
